package com.soushangxing.comfyuibackendv2.config


import com.soushangxing.comfyuibackendv2.repository.ServerRepository
import com.soushangxing.comfyuibackendv2.service.ServerService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.CommandLineRunner
import org.springframework.stereotype.Component

@Component
class StartupRunner : CommandLineRunner {

    @Value("\${dev.startUpRunner}")
    private lateinit var startUpRunner: String

    @Autowired
    lateinit var serverRepository: ServerRepository

    @Autowired
    lateinit var serverService: ServerService

    override fun run(vararg args: String?) {
        println("后端服务已经启动！")
        if (startUpRunner == "true") {
            val serverList = serverRepository.findAll()
            for (server in serverList){
                serverService.startServerByUrl(server.url)
            }
        } else {
            println("这是一个测试模式，所以启动时不主动链接所有服务器！")
        }
    }
}
